package cn.wolfcode.service.impl;

import cn.wolfcode.domain.Permission;
import cn.wolfcode.mapper.PermissionMapper;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IPermissionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

@Service
@Slf4j
public class PermissionServiceImpl implements IPermissionService {

    @Autowired
    private PermissionMapper permissionMapper;

    //private static final Logger log = LoggerFactory.getLogger(PermissionServiceImpl.class);

    @Override
    public int deleteByPrimaryKey(Long id) {
        return permissionMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Permission record) {
        return permissionMapper.insert(record);
    }

    @Override
    public Permission selectByPrimaryKey(Long id) {
        return permissionMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Permission> selectAll() {
        return permissionMapper.selectAll();
    }

    @Override
    public int updateByPrimaryKey(Permission record) {
        return permissionMapper.updateByPrimaryKey(record);
    }

    @Override
    public PageInfo<Permission> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<Permission> Permissions = permissionMapper.selectForList(qo);
        return new PageInfo<>(Permissions);
    }

    @Override
    public void batchInsert(Set<Permission> savedPermissions) {
        permissionMapper.batchInsert(savedPermissions);
    }

    @Override
    public List<String> queryPermissionByEmployeeId(Long employeeId) {
        return permissionMapper.selectPermissionByEmployeeId(employeeId);
    }

    @Override
    public List<Permission> queryPermissionByRoleId(Long roleId) {
        return permissionMapper.queryPermissionByRoleId(roleId);
    }


}
